import axios from 'axios';
import {getToken} from "@/utils/token";

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'

const service = axios.create({
    //后台服务器地址
    baseURL: 'http://192.168.12.23:8090/chat',
    timeout: 10000
});

service.interceptors.request.use(
    config => {
        if (getToken()){
            config.headers['Authorization'] = getToken()
        }
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

export default service;
